package hai.wom.org.qyer_home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import hai.wom.org.qyer_home.R;
import hai.wom.org.qyer_home.bean.Slide_data;

/**
 * Created by Administrator on 2017/1/11 0011.
 */

public class MyAdapter_Fragment_Spot extends BaseAdapter {
    List<Slide_data.DataEntity.SubCateEntity> list;
    Context context;

    public MyAdapter_Fragment_Spot(List<Slide_data.DataEntity.SubCateEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_spot,parent,false);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.iv_item_spot);
            holder.tv= (TextView) convertView.findViewById(R.id.tv_item_spot);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Slide_data.DataEntity.SubCateEntity sub=list.get(position);
        holder.tv.setText(sub.getName());
        Picasso.with(context).load(sub.getCover()).into(holder.iv);

        return convertView;
    }

    class  ViewHolder{
        ImageView iv;
        TextView tv;


    }
}
